package com.authine.cloudpivot.ext.applicationservice;


import com.alibaba.fastjson.JSON;
import com.authine.cloudpivot.ext.dto.GatewayParam;
import com.authine.cloudpivot.ext.model.bosi.BsscReq;
import com.authine.cloudpivot.ext.model.bosi.BsscResp;
import com.authine.cloudpivot.ext.service.BsscService;
import com.authine.cloudpivot.ext.service.impl.BsscServiceImpl;
import com.authine.hermes.app.launcher.service.ApplicationService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import javax.ws.rs.POST;
import javax.ws.rs.Path;

import static com.authine.hermes.app.launcher.service.ApplicationServiceFoundation.CUSTOM_SERVICE;

/**
 * @Author hxd
 * @Date 2021/9/26 19:25
 **/
@Path("PunchoutV1Controller")
@Slf4j
public class PunchoutV1Controller extends ApplicationService {
    private BsscService bsscService = BsscServiceImpl.getInstance();

    @Autowired

    /**
     * 调用固买认证接口
     * 固买原项目路径: bosi/api/mall/auth/login
     */
    @Path("getAuth")
    @POST
    @Operation(summary = "冀中:调用固买认证接口", tags = CUSTOM_SERVICE)
    public BsscResp getAuth(GatewayParam dto) {
        String str = JSON.toJSONString(dto.getBody());
//        log.info("=>=>=>=>=>=>=>=>=>=>=>dto={}",dto);
        BsscReq<String> bsscReq = JSON.parseObject(str, BsscReq.class);
//        log.info("=>=>=>=>=>=>=>=>=>=>=>bsscReq={}", bsscReq);

        return bsscService.getAuth(bsscReq);
    }

    /**
     * 获取品类列表
     * 固买原项目路径: bosi/api/mall/auth/catalog/query
     */
    @Path("getItemList")
    @POST
    @Operation(summary = "冀中:获取品类列表", tags = CUSTOM_SERVICE)
    public BsscResp getItemList(GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getItemList(bsscReq);
    }

    /**
     * 查询商品的库存情况
     * 固买原项目路径: bosi/api/mall/auth/egoods/stock/query
     *
     * @return
     */
    @Path("getGoodsInventory")
    @POST
    @Operation(summary = "冀中:查询商品的库存情况", tags = CUSTOM_SERVICE)
    public BsscResp getGoodsInventory(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getGoodsInventory(bsscReq);
    }

    /**
     * 查询商品价格
     * 固买原项目路径: bosi/api/mall/auth/egoods/price/query
     *
     * @return
     */
    @Path("getGoodsPrice")
    @POST
    @Operation(summary = "冀中:查询商品价格", tags = CUSTOM_SERVICE)
    public BsscResp getGoodsPrice(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getGoodsPrice(bsscReq);
    }

    /**
     * 查询物流信息
     * 固买原项目路径: bosi/api/mall/get/track
     */
    @Path("getLogisticsInformation")
    @POST
    @Operation(summary = "冀中:查询物流信息", tags = CUSTOM_SERVICE)
    public BsscResp getLogisticsInformation(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getLogisticsInformation(bsscReq);
    }

    /**
     * 查询订单系统订单号
     * 固买原项目路径: bosi/api/mall/get/mallOrderNo
     *
     * @return
     */
    @Path("getOrderId")
    @POST
    @Operation(summary = "冀中:查询订单系统订单号", tags = CUSTOM_SERVICE)
    public BsscResp getOrderId(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getOrderId(bsscReq);
    }

    /**
     * 查询电商系统售后单号
     * 固买原项目路径: bosi/api/mall/get/mallAfterSaleNo
     */
    @Path("getMallAfterSaleNo")
    @POST
    @Operation(summary = "冀中:查询电商系统售后单号", tags = CUSTOM_SERVICE)
    public BsscResp getMallAfterSaleNo(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.getMallAfterSaleNo(bsscReq);
    }

    /**
     * 供应商网络会根据业务发出消息指令给电商，电商提供接收消息的监听接口。根据接收到的消息类型进行相关业务处理
     * 固买原项目路径: bosi/api/mall/message/listening
     */
    @Path("messageListening")
    @POST
    @Operation(summary = "冀中:消息监听", tags = CUSTOM_SERVICE)
    public BsscResp messageListening(@RequestBody GatewayParam dto) {
        BsscReq<String> bsscReq = JSON.parseObject(JSON.toJSONString(dto.getBody()), BsscReq.class);
        return bsscService.messageListening(bsscReq);
    }







}
